package com.hh.springboot.controller;

import com.alibaba.fastjson.JSON;
import com.hh.springboot.model.OrderForm;
import com.hh.springboot.model.User;
import com.hh.springboot.service.OrderService;
import com.hh.springboot.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
public class OrderFromDataController {
    @Autowired
    private OrderService orderService;

    @RequestMapping("/addOrder")
    public String addOrder(HttpSession session, PageBean<OrderForm> pageBean) {
        User user = (User) session.getAttribute("user");
        pageBean = orderService.getPageBean(user.getId(), pageBean.getPageNo(), pageBean.getPageSize());
        Map<String, Object> map = new HashMap<>();
        map.put("pageBean", pageBean);
        return JSON.toJSONString(map);
    }
}
